/**
 * Copyright 2012 Roger Cockshutt
 * krakenbrau@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.parallelrl.data;

import java.util.List;
import java.util.Vector;

import com.googlecode.parallelrl.util.Point2D;

/**
 * Makes the current level accessible, and handles level transitions, and saving/loading.
 * (Is this class really necessary?  I don't like it.)
 * 
 * @author Roger Cockshutt
 *
 */
public abstract class LevelProvider {
	
//	private static LevelProvider INSTANCE = null;
//	
//	public static LevelProvider getInstance() {
//		if (INSTANCE == null) {
//			INSTANCE = new LevelProvider();
//		}
//		return INSTANCE;
//	}
//	
//	public static void clearInstance() {
//		INSTANCE = null;
//	}
	
	private static ILevel currentLevel;
	
	private static List<ECSLevel> levels;
	
	static {
		initialize();
	}
	
	public static void initialize() {
		currentLevel = null;
		levels = new Vector<>();
	}
	
	
	
	/**
	 * @return The currently active level.
	 */
	public static ILevel getCurrentLevel() {
		return currentLevel;
	}
	
	/**
	 * Returns a new level of the given size.
	 * 
	 * @param size
	 * @return
	 */
	public static ILevel getNewLevel(Point2D size) {
		ECSLevel newLevel = new ECSLevel(size);
		levels.add(newLevel);
		if (currentLevel == null) {
			currentLevel = newLevel;
		}
		return newLevel;
	}
	
	/**
	 * Loads the level from file.
	 */
	public static void load() {
		DataFile load = new DataFile("test.prl");
		load.read();
		setCurrentLevel(load.loadLevel());
	}
	
	/**
	 * Saves the level to file.
	 */
	public static void save() {
		DataFile save = new DataFile("test.prl");
		save.saveLevel(getCurrentLevel());
		save.write();
	}
	
	/**
	 * @param level The level to be made active.
	 */
	public static void setCurrentLevel(ILevel level) {
		currentLevel = level;
	}

}
